package edu.hrbu.spring.exception.resolver;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * 我们自己实现的一个全局异常处理器
 *
 * @author 徐登宇
 */
//@Component // 因为是Spring去调用它，所以交给Spring容器去管理
public class GlobalHandlerExceptionResovler implements HandlerExceptionResolver {

    @Override
    public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {

        ModelAndView mv = new ModelAndView();
        mv.setViewName("error");
        mv.addObject("ex",ex);

        return mv;
    }
}
